<?php
/**
 * 标签超期取消标签
 * User: Administrator
 * Date: 2018\8\10 0010
 * Time: 16:43
 */

namespace app\lib\Order\OrderMonitor;


use app\lib\Order\OrderExtensionConfig\GetOrderBindingExtension;
use app\lib\Order\OrderExtensionConfig\OrderBindingEditExtension;
use app\model\OrderInfoModel;

class OrderTagMonitor
{
    /**
     * 获取工单数据
     * @return array|bool
     */
    protected function getOrder(){
        $model =  (new OrderInfoModel());
        $map   = [$model->_orderStatus=>1];
        $orderIdArray    = $model->where($map)->column($model->_id);
        if(empty($orderIdArray)){
            return true;
        }
        return $orderIdArray;
    }

    /**
     * 标签超期取消标签
     * @return bool
     * @throws \Exception
     */
    public function save(){
        $data = $this->getOrder();
        foreach ($data as $v){
            $model =  (new GetOrderBindingExtension($v));
            if($model->isOrderBindingExtension() && $model->getEndTime()<time()){
                (new OrderBindingEditExtension($v))->autoReleaseBinding();
            }
        }
        return true;
    }
}